﻿using System.Collections.Generic;
using System.Data;
using System;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class ToWanVolunteer : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            ToWanVolunteerOutParam result = new ToWanVolunteerOutParam();
            ToWanVolunteerInParam param = new ToWanVolunteerInParam();
            string logMsg = "";
            bool isFlag = true;
            string loginName = "";

            try
            {
                param = inParam as ToWanVolunteerInParam;

                if (string.IsNullOrEmpty(param.LoginID))
                {
                    result.code = "0";
                    result.desc = "登录ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (string.IsNullOrEmpty(param.Profession) || string.IsNullOrEmpty(param.Strengths) || string.IsNullOrEmpty(param.ServiceType))
                    {
                        result.code = "0";
                        result.desc = "职业分类、特长、服务类型不能为空";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (param.Profession != "0" && param.Profession != "1" && param.Profession != "2" && param.Profession != "3" && param.Profession != "4"
                         && param.Profession != "5" && param.Profession != "6" && param.Profession != "7" && param.Profession != "8" && param.Profession != "9")
                    {
                        result.code = "0";
                        result.desc = "职业必须为：0 教师;1政府公务员；2军人；3工人；4 农民；5医务人员 ；6科技人员；7企业人员；8待业人员；999 其他";

                        isFlag = false;
                    }
                }

                int WorkYearsInt = 0;
                if (isFlag)
                {
                    try
                    {
                        WorkYearsInt = Convert.ToInt32(param.WorkYears);
                    }
                    catch
                    {
                        result.code = "0";
                        result.desc = "工作年限必须为整型数据";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    DataSet dsLoginName = InterfaceHelper.GetUseInfo(param.LoginID);
                    if (dsLoginName == null || dsLoginName.Tables[0].Rows.Count == 0)
                    {
                        result.code = "0";
                        result.desc = "当前登陆ID无效或者不存在";

                        isFlag = false;
                    }
                    else
                    {
                        loginName = dsLoginName.Tables[0].Rows[0]["userName"].ToString();
                    }
                }

                if (isFlag)
                {
                    ZHDJ.MobileInterface.Common.IWanVolunteer.Volunteer FA = new Common.IWanVolunteer.Volunteer()
                    {
                        WorkUnits = param.WorkUnits,
                        WorkYears = WorkYearsInt,
                        PostCode = param.PostCode,
                        Profession = param.Profession,
                        Strengths = param.Strengths,
                        OtherStrengths = param.OtherStrengths,
                        ServiceType = param.ServiceType,
                        ServiceTime=param.ServiceTime
                    };

                    string rfResult = IWanVolunteer.IWVolunteer(param.LoginID, FA);
                    if (!string.IsNullOrEmpty(rfResult))
                    {
                        result.code = "0";
                        result.desc = rfResult;

                        isFlag = false;
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "转移过程出现异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-ToWanVolunteer", SerializeHelper.JsonSerializer<ToWanVolunteerInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<ToWanVolunteerInParam, ToWanVolunteerOutParam>();
            else
                SafeProcessRequest<ToWanVolunteerInParam, ToWanVolunteerOutParam>();
        }

        private string NameParse(string type, string name)
        {
            if (type != "2")
                return name;

            //（0:特殊教育1：文化辅导2:医疗辅导3：法律援助4:科技服务5：绿化环保6:陪护老幼7：陪护病人8：照顾残障9:心里咨询）
            switch (name)
            {
                case "0":
                    return "特殊教育";
                case "1":
                    return "文化辅导";
                case "2":
                    return "医疗辅导";
                case "3":
                    return "法律援助";
                case "4":
                    return "科技服务";
                case "5":
                    return "绿化环保";
                case "6":
                    return "陪护老幼";
                case "7":
                    return "陪护病人";
                case "8":
                    return "照顾残障";
                case "9":
                    return "心里咨询";
                default:
                    return "";
            }
        }
    }

    #region 请求参数
    public class ToWanVolunteerInParam
    {
        /// <summary>
        /// 登录ID	string	必须
        /// </summary>
        public string LoginID
        { get; set; }

        /// <summary>
        /// 工作单位	String	必须
        /// </summary>
        public string WorkUnits
        { get; set; }

        /// <summary>
        /// 工作年限	int	必须
        /// </summary>
        public string WorkYears
        { get; set; }

        /// <summary>
        /// 邮政编码	string	必须
        /// </summary>
        public string PostCode
        { get; set; }

        /// <summary>
        /// 职业	String	0教师;1政府公务员；2军人；3工人；4 农民；5医务人员 ；6科技人员；7企业人员；8待业人员；999 其他
        /// </summary>
        public string Profession
        { get; set; }

        /// <summary>
        /// 特长	String	0 书法；1画画；2烹饪；3 电脑 4手工制作；5 篮球； 6 乒乓球；7羽毛球；8足球；9唱歌；10 舞蹈；11教育辅导；999 其他
        /// </summary>
        public string Strengths
        { get; set; }

        /// <summary>
        /// 其他特长	String	非必传
        /// </summary>
        public string OtherStrengths
        { get; set; }

        /// <summary>
        /// 服务类型	String	0:特殊教育1：文化辅导2:医疗辅导3：法律援助4:科技服务5：绿化环保6:陪护老幼7：陪护病人8：照顾残障9:心里咨询
        /// </summary>
        public string ServiceType
        { get; set; }

        /// <summary>
        /// 服务时间 String	0：款项 非必传
        /// </summary>
        public string ServiceTime
        { get; set; }


    }
    #endregion

    #region 结果参数
    public class ToWanVolunteerOutParam
    {
        public ToWanVolunteerOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion
}